package com.chapter14.demo3;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * 遍历
 */
public class ForeachStream {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1,3,5,7,9,5);
        //串行迭代流中的每个元素
        list.stream().forEach(x-> System.out.printf("%d ",x));
        System.out.println();

        //串行按照元素原有的顺序迭代
        list.stream().forEachOrdered(x-> System.out.printf("%d ",x));
        System.out.println();

        //并行迭代流中的每个元素(顺序会乱)
        list.parallelStream().forEach(x-> System.out.printf("%d ",x));
        System.out.println();

        //并行按照元素原有的顺序迭代
        list.parallelStream().forEachOrdered(x-> System.out.printf("%d ",x));
    }
}
